<template>
  <el-container>
    <!-- 主页面头部 -->
    <el-header>
      <div>
        <img src="../assets/logo.png" alt="" />
        <span>通用后台管理系统</span>
      </div>
      <el-button round @click="homeOut" icon="el-icon-s-home"> 退出 </el-button>
    </el-header>
    <el-container>
      <!-- 主页面侧边栏 -->
      <el-aside :width="isCollapse ? '65px' : '200px'">
        <button class="toggle_button" @click="fold">|||</button>
        <el-menu
          :default-active="$route.path"
          :collapse-transition="false"
          :collapse="isCollapse"
          unique-opened
          background-color="rgb(173, 233, 198)"
          active-text-color="#000"
          text-color="#000"
          router
        >
          <!-- 一级菜单 -->
          <el-submenu
            :index="menu.id + ''"
            v-for="menu in menulist"
            :key="menu.id"
          >
            <template slot="title">
              <i :class="iconList[menu.id]"></i>
              <span class="menu_title">{{ menu.authName }}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item
              text-color="#000"
              v-for="meunChildren in menu.children"
              :key="meunChildren.id"
              :index="'/' + meunChildren.path"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ meunChildren.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主页面主体部分 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>

export default {
  name: "Home",
  data() {
    return {
      menulist: [],
      iconList: {
        '125': "iconfont icon-user",
        '103': "iconfont icon-tijikongjian",
        '101': "iconfont icon-showpassword",
        '102': "iconfont icon-danju",
        '145': "iconfont icon-baobiao",
      },
      isCollapse: false
    };
  },
  methods: {
    homeOut() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    //获取左侧菜单列表
    getmeunlist() {
      this.$http
        .get("http://127.0.0.1:8888/api/private/v1/menus")
        .then((response) => {
          if (response.data.meta.status !== 200) {
            this.$message.error(response.data.meta.msg);
          } else {
            this.menulist = response.data.data;
          }
        })
        .catch((error) => console.log(error));
    },
    fold() {
      this.isCollapse = !this.isCollapse

    }
  },
  created() {
    this.getmeunlist();
  },
};
</script>

<style >
.el-container {
  height: 100%;
}
.el-header {
  background-color: rgb(113, 63, 160);
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  font-size: 20px;
}
.el-header div img {
  margin-right: 15px;
  height: 50px;
}
.el-header div {
  display: flex;
  align-items: center;
}

.el-aside {
  background-color: rgb(173, 233, 198);
  height: 100%;
}
.toggle_button {
  background-color: rgb(38, 143, 81);
  outline: none;
  border: none;
  width: 100%;
  height: 25px;
  font-size: 15px;
  cursor: pointer;
}
.menu_title {
  margin-left: 10px;
}

.el-main {
  background-color: #fff;
  height: 100%;
}
</style>